package com.zhixiang.xaec.service.safebase.safemeeting.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.core.util.EChartUtils;
import com.zhixiang.xaec.dao.safebase.safemeeting.MeetManageDao;
import com.zhixiang.xaec.entity.safebase.safecultruetrain.CultureActivity;
import com.zhixiang.xaec.entity.safebase.safemeeting.MeetManage;
import com.zhixiang.xaec.service.safebase.safemeeting.MeetManageService;

@Service
public class MeetManageServiceImpl extends BaseServiceImpl<MeetManage, Long> implements MeetManageService{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	@Resource(type=MeetManageDao.class)
	public void setBaseDao(BaseDao<MeetManage,Long> dao) {
		
		setDao(dao);
	}
	@Override
    public String delete(String[] ids)
    {
       for(String id:ids){
           getDao().remove(Long.valueOf(id));
       }
        return null;
    }

  /*  @Override
    public List<TreeObj> treeLoad(String id)
    {
        if(!"".equals(id)&&id!=null){
        List<TreeObj> treelist = new ArrayList<TreeObj>();    
        YearTree yearTree =  yearTreeService.get(Long.valueOf(id));
	        if(yearTree!=null){
		        TreeObj tobj= new TreeObj();
		        tobj.setId(yearTree.getId().toString());
		        tobj.setText(yearTree.getYear());
		        treelist.add(tobj);
		        findchildren(tobj);
		        return treelist;
	        }
        }
        return null;
    }
   
    private void findchildren(TreeObj treeObj){
        List<YearTree> dList = yearTreeService.findByParentId(Long.valueOf(treeObj.getId()));
        if(dList != null&&dList.size()>0) {
            List<TreeObj> treelist = new ArrayList<TreeObj>();
            for (int i = 0; i < dList.size(); i++ )
            {
            	YearTree yearTree =  dList.get(i);
                TreeObj tobj= new TreeObj();
                tobj.setId(yearTree.getId().toString());
                tobj.setText(yearTree.getYear());
                List<YearTree> dd = yearTreeService.findByParentId(yearTree.getId());
                if(dd.size()==0){
                    tobj.setLeaf(true);
                }
                treelist.add(tobj);
            }
            treeObj.setChildren(treelist);
            
            for (int i = 0; i < treelist.size(); i++ )
            {
                TreeObj tbj = treelist.get(i);
                findchildren(tbj);
            }
        }else{
            treeObj.setLeaf(true);
        }
    }  */
    
/*
    @SuppressWarnings("unchecked")
	public String getChartByFtl(String years) {
	    System.out.println(years);
        Map<String, Object> rootMap = new HashMap<String, Object>();
        List  list=getDao().findByHql("select years,id,meetType from MeetManage  group by yearTree.year",new Object[]{});
        rootMap.put("dataList", list);
        return EChartUtils.getChart(rootMap, "chart_meetManage");
    }*/
    
    public String getChartByFtl() {
        Map<String, Object> rootMap = new HashMap<String, Object>();
        List<MeetManage> list=getDao().findByHql("From MeetManage ",new Object[]{});
        Set<Integer> yearSet =new HashSet<Integer>();
        for(MeetManage o :list){
        	Integer years=Integer.parseInt(o.getYears());
        	yearSet.add(years);
        }
        List<Integer>yearList=new ArrayList<Integer>(yearSet);
        Collections.sort(yearList);
      /*  List<Double> foundsList =new ArrayList<Double>();
        for(int i=0;i<yearList.size();i++){
        double sum=0;	
        for(CultureActivity founds :list){
         if(Integer.parseInt(founds.getYears())==yearList.get(i)){
        	sum+=(double)founds.getActivityfunds();
        }
        }
        foundsList.add(sum);
        }*/
        rootMap.put("dataList", yearList);
       // rootMap.put("foundsList", foundsList);
        return EChartUtils.getChart(rootMap, "chart_meetManage");
    }

}
